package walk;

import java.util.List;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ColumnListHandler;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import comm.DbUtils;
import comm.LOG;

public class chc3 extends Thread {

	public static BlockingQueue<String> q = null;

	private static LOG log = new LOG("C:\\csuu\\walk.offset");

	public void run() {

		while (true) {
			String id;
			try {
				id = q.take();

				String url = "http://my.hupu.com/" + id + "";

				Connection c = Jsoup.connect(url);

				c.userAgent("Mozilla/5.0 (Windows NT 6.2; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0");
				c.header("Cookie", "	u=17112821%7Cbm1sMTg2%7C8c2d%7Ce50b2fe9e47a23f8973f3abee0733ebd%7Ce47a23f8973f3abe; ua=62072554; PHPSESSID=04c9500aff27dec9183d74fca35a694e");

				c.referrer("http://my.hupu.com/public/nba");
				Document doc = c.get();

				//Elements es = doc.getElementsContainingOwnText("上次登录");

				System.out.println(id + ",");
				//sleep(300);

			} catch (Exception e) {
				System.out.println(e.getMessage());
			}

		}

	}

	public static void main(String[] args) throws Exception {
		QueryRunner qr = DbUtils.getQueryRunner();
		List<String> ids = qr.query("select id from HID ", new ColumnListHandler<String>("id"));

		chc3.q = new LinkedBlockingQueue(ids);

		for (int i = 0; i < 3; i++) {
			new chc3().start();
		}
	}
}
